/* JS Code for Navigation Bar Interactions */
	
$(function(){
	
	/*==============================
	== INTERACTIONS NAVBAR DROPDOWNS
	================================
	1. Mouseenter - Show Dropdown
	2. Mouseleave - Hide Dropdown
	3. Dropdown Mouseleave - Hide Dropdown
	4. Dropdown Mouseenter - Persist Dropdown
	==============================*/
	var navtimer;
	var navbar = $('#zi .navbar');
	
	// 1. Hover - Show Dropdown
	navbar.find('li').bind('mouseenter',function(){
		navtimer = clearTimeout(navtimer);
		
		// Add Hover Class
		navbar.find('li.hover').removeClass('hover');
		$(this).addClass('hover');
		
		// Hide other dropdowns
		$('#zi .menu:visible').hide();
		
		// Get current menu
		var m = $(this).attr('data-menu');
		if(m){
			var menu = $('#zi .menu.'+m);
		
			// Position and show current menu
			var o = $(this).offset();
			menu.css('left',o.left).show();
		}
	
	// 2. Mouseleave - Hide Dropdown
	}).bind('mouseleave',function(){
		
		// Start hide nav timer
		navtimer = setTimeout("$('#zi .menu:visible').hide();$('#zi .navbar').find('li.hover').removeClass('hover');",100); // Tweak 100 to appropriate timeout
	});
	
	// 3. Dropdown Mouseleave - Hide Dropdown
	$('#zi .menu').bind('mouseleave',function(){
		
		$(this).hide();
		navbar.find('li.hover').removeClass('hover');

	// 4. Dropdown Mouseenter - Persist Dropdown
	}).bind('mouseenter',function(){
		
		// Reset hide nav timer
		navtimer = clearTimeout(navtimer);
	});
});